Skip to content

NEW: Added Focus Events to Input Event Queue#2365

Open
VeraMommersteeg wants to merge 26 commits intodevelopfrom
input/add-focus-events-to-queue
Open

NEW: Added Focus Events to Input Event Queue#2365
VeraMommersteeg wants to merge 26 commits intodevelopfrom
input/add-focus-events-to-queue

Conversation

@VeraMommersteeg
Copy link
Collaborator

@VeraMommersteeg VeraMommersteeg commented Mar 3, 2026

Description

These are the managed changes for the package to introduce a focus event into the event buffer. It no longer listens to the Application.OnFocusChanged and instead changes focus based on the queued event from native. This will help us deal with desync focus state issues to make sure events are being processed in the right state.

Jira tickets:
ISX-2426
ISX-2427

Testing status & QA

Testing done:

  • Ran editor and playmode tests locally
  • Manually tested several Editor Playmode Input Behaviours
  • Built samples as a player and tried several background behaviour settings compared to develop

Testing by QA:

  • General pass against other samples

Overall Product Risks

  • Complexity: Medium - Focus event changes the way events are processed
  • Halo Effect: Low - Most changes are encapsulated to InputManager.cs

Comments to reviewers

I've spend some time cleaning up the OnUpdate a bit, didn't go too crazy and mostly just split up the code a bit in a couple of functions. But since the git diff makes it a bit difficult to see the changes, it might be easier to pull the branch and do a diff that way.

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • JIRA ticket linked, example (case %%). If it is a private issue, just add the case ID without a link.
    • Jira port for the next release set as "Resolved".
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

@VeraMommersteeg VeraMommersteeg self-assigned this Mar 3, 2026
@cla-assistant-unity
Copy link

cla-assistant-unity bot commented Mar 3, 2026

CLA assistant check
All committers have signed the CLA.

@VeraMommersteeg VeraMommersteeg changed the title Input/add focus events to queue Added focus events to queue Mar 3, 2026
@VeraMommersteeg VeraMommersteeg changed the title Added focus events to queue NEW: Added Focus Events to Input Event Queue Mar 4, 2026
@ekcoh ekcoh self-requested a review March 4, 2026 20:06
@VeraMommersteeg VeraMommersteeg marked this pull request as ready for review March 10, 2026 09:32
Copy link
Contributor

@u-pr u-pr bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May require changes

This review identified several issues ranging from critical bugs in event handling to minor code cleanup items. The most significant concerns involve potential stale state during event processing and improper event discarding logic during focus changes in InputManager.cs, which could lead to stuck input states. Additionally, there are some minor performance improvements, concerns regarding profiler marker reliability, and several typos/commented-out code blocks in the test suite.

🤖 Helpful? 👍/👎

@codecov-github-com
Copy link

codecov-github-com bot commented Mar 10, 2026

Codecov Report

Attention: Patch coverage is 88.65979% with 22 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...putsystem/InputSystem/Utilities/DelegateHelpers.cs 50.00% 14 Missing ⚠️
...em/InputSystem/InputManager.LegacyFocusHandling.cs 92.70% 7 Missing ⚠️
...nity.inputsystem/InputSystem/NativeInputRuntime.cs 75.00% 1 Missing ⚠️
@@             Coverage Diff             @@
##           develop    #2365      +/-   ##
===========================================
+ Coverage    77.90%   78.11%   +0.20%     
===========================================
  Files          476      482       +6     
  Lines        97613    98383     +770     
===========================================
+ Hits         76048    76847     +799     
+ Misses       21565    21536      -29     
Flag Coverage Δ
inputsystem_MacOS_2022.3 5.55% <32.59%> (+0.02%) ⬆️
inputsystem_MacOS_2022.3_project 75.40% <86.63%> (+<0.01%) ⬆️
inputsystem_MacOS_6000.0 5.32% <32.59%> (+0.01%) ⬆️
inputsystem_MacOS_6000.0_project 77.30% <86.84%> (+0.01%) ⬆️
inputsystem_MacOS_6000.3 5.32% <32.59%> (+0.01%) ⬆️
inputsystem_MacOS_6000.3_project 77.30% <86.84%> (+0.01%) ⬆️
inputsystem_MacOS_6000.4 5.33% <32.59%> (+0.01%) ⬆️
inputsystem_MacOS_6000.4_project 77.31% <86.84%> (+0.01%) ⬆️
inputsystem_MacOS_6000.5 5.32% <19.51%> (+<0.01%) ⬆️
inputsystem_MacOS_6000.5_project 77.34% <83.50%> (+0.04%) ⬆️
inputsystem_MacOS_6000.6 5.32% <19.51%> (+<0.01%) ⬆️
inputsystem_MacOS_6000.6_project 77.34% <83.50%> (+0.04%) ⬆️
inputsystem_Ubuntu_2022.3_project 75.20% <86.63%> (+<0.01%) ⬆️
inputsystem_Ubuntu_6000.0 5.33% <32.59%> (+0.01%) ⬆️
inputsystem_Ubuntu_6000.0_project 77.10% <86.84%> (+0.01%) ⬆️
inputsystem_Ubuntu_6000.3 5.33% <32.59%> (+0.01%) ⬆️
inputsystem_Ubuntu_6000.3_project 77.10% <86.84%> (+<0.01%) ⬆️
inputsystem_Ubuntu_6000.4 5.34% <32.59%> (+0.01%) ⬆️
inputsystem_Ubuntu_6000.4_project 77.12% <86.84%> (+<0.01%) ⬆️
inputsystem_Ubuntu_6000.5 5.32% <19.51%> (+<0.01%) ⬆️
inputsystem_Ubuntu_6000.5_project 77.15% <83.50%> (+0.03%) ⬆️
inputsystem_Ubuntu_6000.6 5.32% <19.51%> (+<0.01%) ⬆️
inputsystem_Ubuntu_6000.6_project 77.15% <83.50%> (+0.04%) ⬆️
inputsystem_Windows_2022.3 5.55% <32.59%> (+0.02%) ⬆️
inputsystem_Windows_2022.3_project 75.53% <86.63%> (+<0.01%) ⬆️
inputsystem_Windows_6000.0 5.32% <32.59%> (+0.01%) ⬆️
inputsystem_Windows_6000.0_project 77.44% <86.84%> (+0.01%) ⬆️
inputsystem_Windows_6000.3 5.32% <32.59%> (+0.01%) ⬆️
inputsystem_Windows_6000.3_project 77.43% <86.84%> (+<0.01%) ⬆️
inputsystem_Windows_6000.4 5.33% <32.59%> (+0.01%) ⬆️
inputsystem_Windows_6000.4_project 77.43% <86.84%> (+<0.01%) ⬆️
inputsystem_Windows_6000.5 5.32% <19.51%> (+<0.01%) ⬆️
inputsystem_Windows_6000.5_project 77.47% <83.50%> (+0.04%) ⬆️
inputsystem_Windows_6000.6 5.32% <19.51%> (+<0.01%) ⬆️
inputsystem_Windows_6000.6_project 77.47% <83.50%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
Assets/Tests/InputSystem/CoreTests_Actions.cs 98.40% <100.00%> (+0.25%) ⬆️
Assets/Tests/InputSystem/CoreTests_Devices.cs 98.23% <100.00%> (+<0.01%) ⬆️
Assets/Tests/InputSystem/CoreTests_Editor.cs 97.95% <100.00%> (+<0.01%) ⬆️
Assets/Tests/InputSystem/CoreTests_State.cs 96.43% <100.00%> (+0.01%) ⬆️
...ts/Tests/InputSystem/Plugins/EnhancedTouchTests.cs 100.00% <100.00%> (ø)
...ssets/Tests/InputSystem/Plugins/InputForUITests.cs 96.70% <100.00%> (ø)
Assets/Tests/InputSystem/Plugins/UITests.cs 94.68% <100.00%> (+<0.01%) ⬆️
Assets/Tests/InputSystem/Plugins/UserTests.cs 98.20% <100.00%> (+<0.01%) ⬆️
...com.unity.inputsystem/InputSystem/IInputRuntime.cs 80.00% <ø> (ø)
.../com.unity.inputsystem/InputSystem/InputManager.cs 94.13% <ø> (+2.35%) ⬆️
... and 5 more

... and 5 files with indirect coverage changes

@Pauliusd01 Pauliusd01 self-requested a review March 10, 2026 13:04
@Pauliusd01

This comment was marked as off-topic.

# Conflicts:
#	Packages/com.unity.inputsystem/InputSystem/InputManager.cs
#	Packages/com.unity.inputsystem/Tests/TestFixture/InputTestFixture.cs
@ekcoh
Copy link
Collaborator

ekcoh commented Mar 11, 2026

@VeraMommersteeg Looks like the PR currently has conflicts that are in need of being resolved:

  • InputManager.cs
  • InputTestFixture.cs

Likely due to CEPM/FEPM branch being merged.

@ekcoh
Copy link
Collaborator

ekcoh commented Mar 11, 2026

@VeraMommersteeg Noticed there are multiple test failures, I suspect you have already noticed and is looking into it?

@VeraMommersteeg
Copy link
Collaborator Author

Yes Im aware I have changes to fix it locally

Copy link
Collaborator

@ekcoh ekcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just commenting for now as a half-way review. Need to clone this PR in order to have a realistic chance to provide relevant feedback on InputManager.cs diff. Looking at the diff alone is very complex.

@ekcoh
Copy link
Collaborator

ekcoh commented Mar 12, 2026

Tested the current branch locally on 2022.3 and noticed the following:

  • 🟢 Playmate tests in editor succeeding
  • 🔴 Player tests - hangs the player/editor (looks like recursive call to InputManager.Update)
  • 🔴 Editor tests - 3 failures (regressions of behaviour on versions older than 6000.5a8):
    • Move_ShouldMutateDeviceState_WithinPlayModeTestFixtureContext
    • Press_ShouldMutateDeviceState_WithinPlayModeTestFixtureContext
    • Touch_ShouldMutateDeviceState_WithinPlayModeTestFixtureContext

@ekcoh
Copy link
Collaborator

ekcoh commented Mar 12, 2026

Tested the current branch locally on 2022.3 and noticed the following:

  • 🟢 Playmate tests in editor succeeding

  • 🔴 Player tests - hangs the player/editor (looks like recursive call to InputManager.Update)

  • 🔴 Editor tests - 3 failures (regressions of behaviour on versions older than 6000.5a8):

    • Move_ShouldMutateDeviceState_WithinPlayModeTestFixtureContext
    • Press_ShouldMutateDeviceState_WithinPlayModeTestFixtureContext
    • Touch_ShouldMutateDeviceState_WithinPlayModeTestFixtureContext

This seems fine now after last batch of commits.

@VeraMommersteeg
Copy link
Collaborator Author

Those tests are passing on CI though, when I was fixing some tests it ended up in a bad state, might want to restart editor and delete any generated files

Copy link
Collaborator

@ekcoh ekcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this comprehensive work @VeraMommersteeg. Changes looks great and I couldn't spot anything that looks incorrect, but added some additional nitpick-level comments.
I like that legacy behaviour has been split out from InputManager since this was already partial that just simplifies removing legacy behaviour later.
I also like that you have added inline comments motivating complex behaviour in update loop (or indirect sub-parts of update), I also think its great you took some time to refactor / break up the update flow and its great you managed to keep many parts shared between legacy and new.

The only thing I would recommend checking either before or after this lands, would be to compare performance test results locally or in observer to check that the differences in event queue processing doesn't generate any performance regression. Functional correctness of course has higher priority, but we could negatively affect the update loop with these changes. IMO such performance issues should not prevent this from landing, but if we find anomalies we should likely try to address it. Great job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants